home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_006 / microemacs / tcap.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  128 lines

  1. #include <stdio.h>
  2. #include "ed.h"
  3.  
  4. #if TERMCAP
  5.  
  6. #define NROW    24
  7. #define NCOL    80
  8. #define BEL     0x07
  9. #define ESC     0x1B
  10.  
  11. extern int      ttopen();
  12. extern int      ttgetc();
  13. extern int      ttputc();
  14. extern int      ttflush();
  15. extern int      ttclose();
  16. extern int      tcapmove();
  17. extern int      tcapeeol();
  18. extern int      tcapeeop();
  19. extern int      tcapbeep();
  20. extern int      tcapopen();
  21. extern int      tput();
  22. extern char     *tgoto();
  23.  
  24. #define TCAPSLEN 315
  25.  
  26. char tcapbuf[TCAPSLEN];
  27. char    PC,
  28.         *CM,
  29.         *CL,
  30.         *CE,
  31.         *UP,
  32.         *CD;
  33.  
  34.  
  35. TERM term = {
  36.         NROW-1,
  37.         NCOL,
  38.         &tcapopen,
  39.         &ttclose,
  40.         &ttgetc,
  41.         &ttputc,
  42.         &ttflush,
  43.         &tcapmove,
  44.         &tcapeeol,
  45.         &tcapeeop,
  46.         &tcapbeep
  47. };
  48.  
  49. tcapopen()
  50.  
  51. {
  52.         char *getenv();
  53.         char *t, *p, *tgetstr();
  54.         char tcbuf[1024];
  55.         char *tv_stype;
  56.         char err_str[72];
  57.  
  58.         if ((tv_stype = getenv("TERM")) == NULL)
  59.         {
  60.                 puts("Environment variable TERM not defined!");
  61.                 exit(1);
  62.         }
  63.  
  64.         if((tgetent(tcbuf, tv_stype)) != 1)
  65.         {
  66.                 sprintf(err_str, "Unknown terminal type %s!", tv_stype);
  67.                 puts(err_str);
  68.                 exit(1);
  69.         }
  70.  
  71.         p = tcapbuf;
  72.         t = tgetstr("pc", &p);
  73.         if(t)
  74.                 PC = *t;
  75.  
  76.         CD = tgetstr("cd", &p);
  77.         CM = tgetstr("cm", &p);
  78.         CE = tgetstr("ce", &p);
  79.         UP = tgetstr("up", &p);
  80.  
  81.         if(CD == NULL || CM == NULL || CE == NULL || UP == NULL)
  82.         {
  83.                 puts("Incomplete termcap entry\n");
  84.                 exit(1);
  85.         }
  86.  
  87.         if (p >= &tcapbuf[TCAPSLEN])
  88.         {
  89.                 puts("Terminal description too big!\n");
  90.                 exit(1);
  91.         }
  92.         ttopen();
  93. }
  94. tcapmove(row, col)
  95. register int row, col;
  96. {
  97.         putpad(tgoto(CM, col, row));
  98. }
  99.  
  100. tcapeeol()
  101. {
  102.         putpad(CE);
  103. }
  104.  
  105. tcapeeop()
  106. {
  107.         putpad(CD);
  108. }
  109.  
  110. tcapbeep()
  111. {
  112.         ttputc(BEL);
  113. }
  114.  
  115. putpad(str)
  116. char    *str;
  117. {
  118.         tputs(str, 1, ttputc);
  119. }
  120.  
  121. putnpad(str, n)
  122. char    *str;
  123. {
  124.         tputs(str, n, ttputc);
  125. }
  126. #endif TERMCAP
  127.  
  128.